using UnityEngine;
using QFramework;
using System.Collections;
using Unity.VisualScripting;
using UnityEngine.PlayerLoop;

// 1.请在菜单 编辑器扩展/Namespace Settings 里设置命名空间
// 2.命名空间更改后，生成代码之后，需要把逻辑代码文件（非 Designer）的命名空间手动更改
namespace QFramework.Example
{
	/// <summary>
	/// 单独控制player升级的等级控制器
	/// </summary>
	public partial class LevelUpManager : ViewController,ICanReadModels,IController
	{
        public IArchitecture GetArchitecture()
        {
            return Global.Interface;
        }

        public void ReadModels()
        {
            DataManager.Instance.playerModel.PlayerLevel.Register(value =>
            {
                StartCoroutine(LevelUp());

            }).UnRegisterWhenGameObjectDestroyed(gameObject);
        }

		

        void Start()
		{
            ResKit.Init();
			ReadModels();

        }

        void Update()
        {
            if (Input.GetKeyDown(KeyCode.P))
            {
                DataManager.Instance.playerModel.PlayerLevel.Value += 1;
            }
        }


        IEnumerator  LevelUp()
        {
            Time.timeScale = 0;
            LeveUpAnim.updateMode = AnimatorUpdateMode.UnscaledTime;
            LeveUpAnim.Play("LevelUp");
            float animTime = LeveUpAnim.GetCurrentAnimatorStateInfo(0).length;
            yield return new WaitForSecondsRealtime(animTime);
            UIKit.OpenPanel<UI_AbilityPanel>();
        }

    }
}
